/**
 * Copyright (C), 2015-2024, XXX有限公司
 * FileName: KafkaConsumerTest
 * Author:   Administrator
 * Date:     2024/3/27 21:20
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.ProducerConfig;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author Administrator
 * @create 2024/3/27
 * @since 1.0.0
 */
public class KafkaConsumerTest {

    public static void main(String[] args) {
        //TODO 创建消费者
        Map<String, String> config = new HashMap<String, String>();
        config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "113.249.93.63:9092");
        config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
        config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
        config.put(ConsumerConfig.GROUP_ID_CONFIG, "test");
        KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(config);
        consumer.subscribe(Collections.singletonList("test"));
        final Consumer<ConsumerRecord<String, String>> consumerRecordConsumer = new Consumer<ConsumerRecord<String, String>>() {
            @Override
            public void accept(ConsumerRecord<String, String> stringStringConsumerRecord) {
                System.out.println(stringStringConsumerRecord.value());
            }
        };
        //TODO 消费数据
        consumer.close();
    }
}